package config

import (
	"database/sql"
	"math/rand"
	"time"
)

/*
按照玩家盈利金额，设置进入假PG的百分比
*/
type CfgEntryFakePGItem struct {
	TotalWin        float64 `json:"TotalWin" db:"TotalWin" cbor:"TotalWin"`
	EntryFakePGRate int     `json:"EntryFakePGRate" db:"EntryFakePGRate" cbor:"EntryFakePGRate"`
}
type CsEntryFakePGCfg struct{}

var CfgEntryFakePGList []CfgEntryFakePGItem

func (that *CsEntryFakePGCfg) GetCfg() []CfgEntryFakePGItem {
	return CfgEntryFakePGList
}

func (that *CsEntryFakePGCfg) removeAllCfg() {
	CfgEntryFakePGList = []CfgEntryFakePGItem{}
}

func EntryFakePGCfgRemove() {
	CfgEntryFakePGList = []CfgEntryFakePGItem{}
}

func EntryFakePGCfgSetRow(rows *sql.Rows) {
	var tVal CfgEntryFakePGItem
	var err error
	err = rows.Scan(&tVal.TotalWin, &tVal.EntryFakePGRate)
	if err == nil {
		CfgEntryFakePGList = append(CfgEntryFakePGList, tVal)
	}
}

func CanEntryFakcePG(userTotalWin float64) bool {
	var EntryFakcePGRate int
	for _, value := range CfgEntryFakePGList {
		if userTotalWin >= value.TotalWin {
			EntryFakcePGRate = value.EntryFakePGRate
			break
		}
	}

	rand.New(rand.NewSource(time.Now().UnixNano()))
	randValue := rand.Intn(100)

	if randValue >= EntryFakcePGRate {
		return false
	} else {
		return true
	}
}
